#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include<sys/stat.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv)
{
	int cfd;
	int recbyte;
	int sin_size;
	char buffer[1024*1024*50] = {0};

	struct sockaddr_in s_add, c_add;
	unsigned short portnum = 2333;

	printf("Hello,welcome to client!\r\n");

	if(argc != 3)
	{
			printf("usage: echo ip\n");
			return -1;
	}

	cfd = socket(AF_INET, SOCK_STREAM, 0);
	if(-1 == cfd)
	{
			printf("socket fail ! \r\n");
			return -1;
	}

	printf("socket ok !\r\n");

	bzero(&s_add,sizeof(struct sockaddr_in));
	s_add.sin_family=AF_INET;
	s_add.sin_addr.s_addr= inet_addr(argv[1]);
	s_add.sin_port=htons(portnum);
	printf("s_addr = %#x ,port : %#x\r\n",s_add.sin_addr.s_addr,s_add.sin_port);

	if(-1 == connect(cfd,(struct sockaddr *)(&s_add), sizeof(struct sockaddr)))
	{
			printf("connect fail !\r\n");
			return -1;
	}

	printf("connect ok !\r\n");
    char *IOtest = argv[2];
    int fd;
    send(cfd,IOtest,strlen(IOtest),0);
    if((fd = open(IOtest,O_RDWR,0777))<0){
		printf("open %s failed!\n",IOtest);
	}else{
	    struct stat stat_buf;
        fstat(fd,&stat_buf);
	    sendfile(cfd,fd,NULL,stat_buf.st_size);}


	close(cfd);

	return 0;

}
